#!/bin/bash

# Init prefix
PREFIX="/usr/local"

# Parse arguments with getopts
while getopts hp: opt
do case "$opt" in
	p)	PREFIX=$OPTARG;;
	h)	echo "Usage: configure [-h] [-p prefix_dir]"
		echo
		echo "	-h  :Print this help message."
		echo "	-p  :Pass custom install directory."
		echo "		(defaults to /usr/local)";;
	[?]) echo "Usage: configure [-h] [-p prefix_dir]";;
	esac
done

# Function to generate installation files
gen() {
	sed -e "s|@APP_DIR|$PREFIX|g" "$1.in" > "$1" 
	chmod +x "$1"
}

# Generate executable and Makefile
gen bin/dargite3d
gen Makefile
